package estandares;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class AplicacionNumero extends JFrame implements ActionListener
{
    private static JLabel lblnum1, lblnum2, lblnum3, lblres;
    private static JTextField txtnum1, txtnum2, txtnum3, txtres;
    private static JButton btnmen;
    private Color c1,c2;
    
    public AplicacionNumero()
    {
        //Formulario Principal
        setLayout( null );
        //setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOSE );
        setBounds( 0, 0, 350, 350 );
        setLocationRelativeTo( null );
        setTitle( "NUMERO MENOR" );
        setVisible( false );
        
        c1 = new Color(237,245,137);
	c2 = new Color(255,255,255);
        
        lblnum1 = new JLabel( "Numero 1: " );
        lblnum1.setBounds(30, 30, 100, 30);
        add( lblnum1 );
        
        txtnum1 = new JTextField("");
        txtnum1.setBounds(150, 30, 120, 30);
        add( txtnum1 );
        
        lblnum2 = new JLabel( "Numero 2: " );
        lblnum2.setBounds(30, 80, 100, 30);
        add( lblnum2 );
        
        txtnum2 = new JTextField("");
        txtnum2.setBounds(150, 80, 120, 30);
        add( txtnum2 );
        
        lblnum3 = new JLabel( "Numero 3: " );
        lblnum3.setBounds(30, 130, 100, 30);
        add( lblnum3 );
        
        txtnum3 = new JTextField("");
        txtnum3.setBounds(150, 130, 120, 30);
        add( txtnum3 );
        
        lblres = new JLabel( "El # menor es: " );
        lblres.setBounds(30, 180, 100, 30);
        add( lblres );
        
        txtres = new JTextField("");
        txtres.setBounds(150, 180, 120, 30);
        add( txtres );
        
        btnmen = new JButton("Menor");
        btnmen.setBounds(150, 230, 120, 30);
        add ( btnmen );
        
        
    }
    
    public int Respuesta( int num1, int num2, int num3 )
    {
        if ( num1 < num2 && num1 < num3 )
        {
            return num1;
        }
        else
        {
            if ( num2 < num1 && num2 < num3 )
            {
                return num2;
            }
            else
            {
                if ( num3 < num1 && num3 < num2 )
                {
                    return num2;
                }
                else
                {
                    if ( num1 == num2 && num1 == num3 )
                    {
                        return num1;
                    }
                }
            }
        }
        return num1;
    }
    
    public void actionPerformed( ActionEvent e)
    {
        int num1, num2, num3, res;
        
        if ( e.getSource() == btnmen )
        {     
            System.out.print("Hola");
            num1 = Integer.parseInt(txtnum1.getText());
            if ( !(num1 == 0) )
            {
                num2 = Integer.parseInt(txtnum2.getText());
                if ( !(num2 == 0) )
                {
                    num3 = Integer.parseInt(txtnum3.getText());
                    if ( !(num3 == 0) )
                    {
                        res = Respuesta( num1, num2, num3);
                        txtres.setText("El # es "+res);
                    }
                    else
                    {
                            txtnum1.setBackground(c1);
                            JOptionPane.showMessageDialog(this, "Falta digitar número.");
                            txtnum1.setBackground(c2);
                    } 
                }
                else
                {
                        txtnum2.setBackground(c1);
                        JOptionPane.showMessageDialog(this, "Falta digitar número.");
                        txtnum2.setBackground(c2);
                }           
            }
            else
            {
                    txtnum3.setBackground(c1);
                    JOptionPane.showMessageDialog(this, "Falta digitar número.");
                    txtnum3.setBackground(c2);
            }
        }
        
    }
    
    
}
